package com.ruoyi.web.controller.campus;

import java.util.List;
import java.util.UUID;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.campus.domain.MyCommimages;
import com.ruoyi.campus.service.IMyCommimagesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品图片Controller
 *
 * @author zht
 * @date 2021-10-24
 */
@RestController
@RequestMapping("/campus/commimages")
public class MyCommimagesController extends BaseController
{
    @Autowired
    private IMyCommimagesService myCommimagesService;

    /**
     * 查询商品图片列表
     */
    @PreAuthorize("@ss.hasPermi('campus:commimages:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyCommimages myCommimages)
    {
        startPage();
        List<MyCommimages> list = myCommimagesService.selectMyCommimagesList(myCommimages);
        return getDataTable(list);
    }

    /**
     * 导出商品图片列表
     */
    @PreAuthorize("@ss.hasPermi('campus:commimages:export')")
    @Log(title = "商品图片", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyCommimages myCommimages)
    {
        List<MyCommimages> list = myCommimagesService.selectMyCommimagesList(myCommimages);
        ExcelUtil<MyCommimages> util = new ExcelUtil<MyCommimages>(MyCommimages.class);
        return util.exportExcel(list, "商品图片数据");
    }

    /**
     * 获取商品图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:commimages:query')")
    @GetMapping(value = "/{imgId}")
    public AjaxResult getInfo(@PathVariable("imgId") String imgId)
    {
        return AjaxResult.success(myCommimagesService.selectMyCommimagesByImgId(imgId));
    }

    /**
     * 新增商品图片
     */
    @PreAuthorize("@ss.hasPermi('campus:commimages:add')")
    @Log(title = "商品图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyCommimages myCommimages)
    {
        myCommimages.setImgId(UUID.randomUUID().toString().replace("-",""));
        return toAjax(myCommimagesService.insertMyCommimages(myCommimages));
    }

    /**
     * 修改商品图片
     */
    @PreAuthorize("@ss.hasPermi('campus:commimages:edit')")
    @Log(title = "商品图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyCommimages myCommimages)
    {
        return toAjax(myCommimagesService.updateMyCommimages(myCommimages));
    }

    /**
     * 删除商品图片
     */
    @PreAuthorize("@ss.hasPermi('campus:commimages:remove')")
    @Log(title = "商品图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imgIds}")
    public AjaxResult remove(@PathVariable String[] imgIds)
    {
        return toAjax(myCommimagesService.deleteMyCommimagesByImgIds(imgIds));
    }
}
